package com.sgb.kjwl.view.ui.activity.pick;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.RequiresApi;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.apeng.permissions.EsayPermissions;
import com.apeng.permissions.OnPermission;
import com.chuanglan.shanyan_sdk.OneKeyLoginManager;
import com.chuanglan.shanyan_sdk.listener.OneKeyLoginListener;
import com.chuanglan.shanyan_sdk.listener.OpenLoginAuthListener;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.tabs.TabLayout;
import com.sgb.alimaplibrary.MapLocationTools;
import com.sgb.alimaplibrary.util.ToastUtil;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.api.GsonManager;
import com.sgb.kjwl.api.UrlConfig;
import com.sgb.kjwl.databinding.ActivityTentersDetails3Binding;
import com.sgb.kjwl.di.pick.DaggerPickComponent;
import com.sgb.kjwl.di.pick.PickModule;
import com.sgb.kjwl.model.entity.LoginEntity;
import com.sgb.kjwl.model.entity.UserMsgEntity;
import com.sgb.kjwl.model.entity.pick.PickRecordCount;
import com.sgb.kjwl.model.entity.pick.TenderAddenduEntity;
import com.sgb.kjwl.model.entity.pick.TenderDetailEntity3;
import com.sgb.kjwl.model.entity.pick.TenderInfoMainEntity3;
import com.sgb.kjwl.model.entity.pick.TenderInquiryType;
import com.sgb.kjwl.model.entity.user.OneKeyLoginEntity;
import com.sgb.kjwl.utils.ConfigUtils;
import com.sgb.kjwl.utils.NumberConstant;
import com.sgb.kjwl.view.event.LoginEvent;
import com.sgb.kjwl.view.event.self.MachinePublishEvent;
import com.sgb.kjwl.view.ui.activity.MainActivity;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.sgb.kjwl.view.ui.activity.manage.WebsiteInfoActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.GetPositionActivity;
import com.sgb.kjwl.view.ui.activity.self.userInfo.VerificationCodeLoginActivity;
import com.sgb.kjwl.view.ui.adapter.pick.PickAddViewAdapter;
import com.sgb.kjwl.view.ui.adapter.pick.TenderDetailsAdapter;
import com.sgb.kjwl.view.widget.pick.PickBiddinglistDetaiView;
import com.sgb.kjwl.view.widget.pick.PickDetailInquiryView;
import com.sgb.kjwl.view.widget.pick.PickDetailRuleView;
import com.sgb.kjwl.view.widget.pick.PickDetailSupplementView;
import com.sgb.kjwl.view.widget.pick.PickEmploymentShareDialog;
import com.sgb.kjwl.view.widget.pick.TenderDetailsPopWindow;
import com.sgb.kjwl.viewmodel.pick.TenderDetailsModel3;
import com.sgb.link.view.widget.ExpandedTextView;
import com.swgk.core.BaseAppHelper;
import com.swgk.core.base.aroute.AppRouteConstant;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.dialog.RoundCornerDialog;
import com.swgk.core.event.EventConstant;
import com.swgk.core.mmkvutil.CacheMarker;
import com.swgk.core.mmkvutil.MkvUtils;
import com.swgk.core.util.ClickUtils;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.lang.reflect.Field;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
*@author 毁灭霸者
*@date 2020/4/30
*description: 工程分包详情界面
*/
@Route(path = AppRouteConstant.ZhaoCai.ROUTER_PATH_ZC_TENDERDETAILSACTIVITY)
public class TenderDetailsActivity3 extends AppActivity {
    private ActivityTentersDetails3Binding binding;
    private String tenderId;
    private List<String> titles = new ArrayList<>();
    private int selectPos = 0;
    private long midTime;
    private String info;
    private int type;
    private int comType;

    @Inject
    TenderDetailsModel3 viewModel;
    TenderDetailEntity3 tenderDetailEntity3;
    private String customerServiceContactsId = "";
    private List<TenderAddenduEntity> tenderAddenduEntityList;
    private TenderDetailsPopWindow tenderDetailsPopWindow;
    private Boolean haveList = false;    //是否有清单
    private Boolean haveOffer = false;
    private Boolean haveAddendu = false;
    private Boolean haveInquireByLetter = false;
    private Boolean scrolledFirst = true;
    private List<TenderInquiryType> tenderInquiryTypeList;
    private MapLocationTools mapLocationTools;
    private boolean updateData = true;

    private boolean success;
    public static void start(Context context, String no, int type) {
        Intent intent = new Intent();
        intent.setClass(context, TenderDetailsActivity3.class);
//        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.putExtra("NO", no);
        intent.putExtra("type", type);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerPickComponent.builder()
                .appComponent(appComponent)
                .pickModule(new PickModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
    }

    @Override
    protected boolean statusBarDark() {
        return false;
    }

    @SuppressLint("NewApi")
    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(
                TenderDetailsActivity3.this,
                R.layout.activity_tenters_details3);
        binding.setViewModel(viewModel);
        binding.topLayout.ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });
        binding.bidLayout.setOnClickListener(this);
        binding.pickCompany.setOnClickListener(this);
        binding.tvCommit.setOnClickListener(this);
        binding.tvApplication.setOnClickListener(this);
        binding.tvInquireByLetter.setOnClickListener(this);
        binding.tvContactService.setOnClickListener(this);
        binding.tvReport.setOnClickListener(this);
        binding.focusState.setOnClickListener(this);
        binding.lineUserFocus.setOnClickListener(this);
        binding.imgBackTop.setOnClickListener(this);
        binding.topLayout.shareImageView.setOnClickListener(this);

    }

    @Override
    protected void init() {
        DialogHelper.showProgressDialog(TenderDetailsActivity3.this, null, "请求中...", 0, false, null).setCanceledOnTouchOutside(false);
        tenderId = getIntent().getStringExtra("NO");
    }

    /**
     * 得到招标详情除了补遗之外所有数据请求返回
     *
     * @param tenderDetailEntity3
     */
    public void showPagerView(TenderDetailEntity3 tenderDetailEntity3) {
        updateData = false;
        this.tenderDetailEntity3 = tenderDetailEntity3;
        sitDetailsView();
        viewModel.tenderingAddendumPage(false, tenderId);
    }

    /**
     * 补遗数据返回
     *
     * @param data
     */
    public void setAddendumData(List<TenderAddenduEntity> data) {
        if (data != null && data.size() > 0) {
            tenderAddenduEntityList = data;
        }
        viewModel.findTenderInquiryPage(false, tenderId);
    }

    public void setTenderInquiry(List<TenderInquiryType> data) {
        if (data != null && data.size() > 0) {
            tenderInquiryTypeList = data;
        }
        initTabView(tenderDetailEntity3);
    }

    /**
     * 通过接口请求数据来显示当前界面内容
     */
    private void sitDetailsView() {

        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        binding.recyclerTenderMain.setLayoutManager(layoutManager);
        TenderDetailsAdapter tenderDetailsAdapter = new TenderDetailsAdapter(getActivity(), tenderDetailEntity3);
        binding.recyclerTenderMain.setAdapter(tenderDetailsAdapter);

        tenderDetailsAdapter.setOnItemClick(new TenderDetailsAdapter.OnItemClick() {
            @Override
            public void onMapClick(String lat, String lag, String address) {
                PickCompanyLocationMapActivity.start(TenderDetailsActivity3.this, lat, lag, address, viewModel.tenderInfoMainEntity3.get().getComName());
            }

            @Override
            public void onDistanceClick(String lat, String lag, String address) {
                if (TextUtils.isEmpty(lat) || TextUtils.isEmpty(lag)){
                    MToast.showToast(BaseAppHelper.get().getInstance(),"经纬度异常，不能跳转");
                    return;
                }
                Double latt = Double.valueOf(lat);
                Double log = Double.valueOf(lag);
                GetPositionActivity.start(getActivity(), log, latt, address);
            }

        });
        TenderInfoMainEntity3 tenderInfoMainEntity3 = tenderDetailEntity3.getTenderInfoMainEntity3();

        if (tenderInfoMainEntity3.getBiddingOrganizationForm() == 1) {    //"招标组织形式 1-自行组织 2-委托招标"
            binding.focusState.setVisibility(View.VISIBLE);
            binding.back.setVisibility(View.VISIBLE);
        } else if (tenderInfoMainEntity3.getBiddingOrganizationForm() == 2) {
            binding.focusState.setVisibility(View.GONE);
            binding.back.setVisibility(View.GONE);
        }
        //企业是否关注
        if (tenderInfoMainEntity3.isConcernEnterprises()) {
            binding.focusState.setText("已关注");
            binding.focusState.setTextColor(getResources().getColor(R.color.color_999999));
            binding.focusState.setBackgroundResource(R.drawable.corner5_999999_bg);
        } else {
            binding.focusState.setText("关注");
            binding.focusState.setTextColor(getResources().getColor(R.color.color_main));
            binding.focusState.setBackgroundResource(R.drawable.corner5_ff2928_bg_pick);
        }

        updateUserFocusBg();

        customerServiceContactsId = tenderInfoMainEntity3.getCustomerServiceContactsId();
        if (tenderInfoMainEntity3.getName().length() <= 15) {
            binding.topLayout.titleView.setText(tenderInfoMainEntity3.getName());
        } else {
            binding.topLayout.titleView.setText(tenderInfoMainEntity3.getName().substring(0, 12) + "...");
        }

        binding.topLayout.shareImageView.setVisibility(View.VISIBLE);
//        if (TextUtils.isEmpty(tenderInfoMainEntity3.getEndTime())) {
//            binding.llEndTimeTag.setVisibility(View.GONE);
//        } else {
//            binding.llEndTimeTag.setVisibility(View.VISIBLE);
//        }

        if (TextUtils.isEmpty(tenderInfoMainEntity3.getLogo()) || "".equals(tenderInfoMainEntity3.getLogo())) {
            binding.imgLogo.setBackground(this.getResources().getDrawable(R.drawable.pick_company));
        }

        binding.tvIsApply.setVisibility(View.VISIBLE);

        updateView(tenderDetailEntity3.getTenderInfoMainEntity3());

        // 招标方式：1、资格预审；2、资格后审；3、报价即报名
        if (TextUtils.isEmpty(tenderInfoMainEntity3.getVerticalTypeName())) {
            binding.tvTypeName.setVisibility(View.GONE);
        } else {
            binding.tvTypeName.setVisibility(View.VISIBLE);
            binding.tvTypeName.setText(tenderInfoMainEntity3.getVerticalTypeName());
        }

        //新增 “招标轮次”     “招标预告”、“招标报名”、“即将招标”状态不显示，其他状态显示
        String bidRotation = tenderInfoMainEntity3.getBidRotation();
        int state = tenderInfoMainEntity3.getState();
        if (bidRotation == null || bidRotation == "" || state == 1 || state == 8 || state == 9) {
            binding.tvWheelNum.setVisibility(View.GONE);
        } else {
            binding.tvWheelNum.setVisibility(View.VISIBLE);
            binding.tvWheelNum.setText("第" + bidRotation + "轮");
        }

        //增加招标方式：公开招标、邀请招标
//        String biddingMethodName = tenderInfoMainEntity3.getBiddingMethodName();
//        if( !TextUtils.isEmpty(biddingMethodName)){
//            binding.tvType3.setVisibility(View.VISIBLE);
//            if ("公开招标".equals(biddingMethodName)){
//                binding.tvType3.setBackground(getResources().getDrawable(R.drawable.bg_green));
//            }else{
//                binding.tvType3.setBackground(getResources().getDrawable(R.drawable.bg_orange));
//            }
//            binding.tvType3.setText(biddingMethodName);
//        }

    }

    private void updateView(TenderInfoMainEntity3 tenderInfoMainEntity3){
        int rotation = 0;
        if (tenderInfoMainEntity3.getBidRotation() != null && tenderInfoMainEntity3.getBidRotation() != "") {
            rotation = Integer.parseInt(tenderInfoMainEntity3.getBidRotation());
        } else {
            rotation = 0;
        }

        String ApplyEndTime = tenderInfoMainEntity3.getApplyEndTime();

        if (tenderInfoMainEntity3.getState() == 9) { //我要报名
            if (ApplyEndTime != null)
                timeBefore(ApplyEndTime, "报名结束倒计时：");

            if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                updateViewData(0, "招标报名", "我要报名", View.GONE);
            } else {
                binding.tvIsApply.setText("招标报名");
                if (!tenderDetailEntity3.getTenderAuthority()) {
                    if ("0".equals(tenderInfoMainEntity3.getApplyStates())) {   //投标状态(0、未报名,1、已报名,4、待投标,5、已投标,8、中标,15、落标,20、待定标)

                        if (tenderInfoMainEntity3.getVerticalTypeValue() == 3) {
                            if (tenderInfoMainEntity3.ischeckApplay()) {
                                updateViewData(0, "", "我要报名&报价", View.GONE);
                            } else {
                                updateViewData(1, "", "我要报名&报价", View.GONE);
                            }
                        } else {
                            if (tenderInfoMainEntity3.ischeckApplay()) {
                                updateViewData(0, "", "我要报名", View.GONE);
                            } else {
                                updateViewData(1, "", "我要报名", View.GONE);
                            }
                        }

                    } else if ("1".equals(tenderInfoMainEntity3.getApplyStates())) {

                        if (tenderInfoMainEntity3.getVerticalTypeValue() == 3) {
                            updateViewData(0, "", "再次报名&报价", View.GONE);
                        } else {
                            updateViewData(0, "", "再次报名", View.GONE);
                        }

                    } else if ("15".equals(tenderInfoMainEntity3.getApplyStates())) {
                        if (tenderInfoMainEntity3.getVerticalTypeValue() == 3) {
                            updateViewData(1, "", "我要报名&报价", View.GONE);
                        } else {
                            updateViewData(1, "", "我要报名", View.GONE);
                        }
                    } else{
                        updateViewData(0, "招标报名", "我要报名", View.GONE);
                    }
                }
            }

        }
        // 即将招标
        else if (tenderInfoMainEntity3.getState() == 1) {

            if (tenderInfoMainEntity3.getEndTime() != null)
                timeBefore(tenderInfoMainEntity3.getEndTime(), "投标开始时间：");


            if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                updateViewData(1, "即将招标", "我要投标", View.GONE);
            } else {
                binding.tvIsApply.setText("即将招标");
                if (!tenderDetailEntity3.getTenderAuthority()) {
                    if (tenderInfoMainEntity3.getVerticalTypeValue() != 3) {
                        if ("0".equals(tenderInfoMainEntity3.getApplyStates())) {
                            if (tenderInfoMainEntity3.ischeckApplay()) {
                                updateViewData(1, "", "我要投标", View.VISIBLE);
                            } else {
                                updateViewData(1, "", "我要投标", View.GONE);
                            }
                        } else if ("1".equals(tenderInfoMainEntity3.getApplyStates())) {
                            updateViewData(1, "", "我要投标", View.GONE);
                        } else{
                            updateViewData(1, "", "我要投标", View.GONE);
                        }
                    }
                }
            }

        }
        //我要投标   //再次投标
        else if (tenderInfoMainEntity3.getState() == 2 || tenderInfoMainEntity3.getState() == 6) {

            if (tenderInfoMainEntity3.getRotationEndTime() != null && tenderInfoMainEntity3.getState() == 6)
                timeBefore(tenderInfoMainEntity3.getRotationEndTime(), "投标结束倒计时：");

            if (tenderInfoMainEntity3.getEndTime() != null && tenderInfoMainEntity3.getState() == 2)
                timeBefore(tenderInfoMainEntity3.getEndTime(), "投标结束倒计时：");


            if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                updateViewData(0, "正在招标", "我要投标", View.GONE);
            } else {
                if (!tenderDetailEntity3.getTenderAuthority()) {
                    if ("0".equals(tenderInfoMainEntity3.getApplyStates())) {
                        if (rotation == 1) {
                            if (tenderInfoMainEntity3.getVerticalTypeValue() == 2) {   //1、资格预审；2、资格后审；
                                if (tenderInfoMainEntity3.ischeckApplay()) {
                                    updateViewData(1, "正在招标", "我要投标", View.VISIBLE);
                                } else {
                                    updateViewData(1, "正在招标", "我要投标", View.GONE);
                                }
                            } else if (tenderInfoMainEntity3.getVerticalTypeValue() == 1) {
                                updateViewData(1, "正在招标", "我要投标", View.GONE);
                            }
                        } else if (rotation >= 2) {
                            updateViewData(1, "正在招标", "我要投标", View.GONE);
                        }
                    } else if ("4".equals(tenderInfoMainEntity3.getApplyStates())) {
                        if (tenderInfoMainEntity3.getVerticalTypeValue() != 3 && rotation == 1) {
                            updateViewData(0, "正在招标", "我要投标", View.GONE);
                        }
                    } else if ("5".equals(tenderInfoMainEntity3.getApplyStates())) {
                        updateViewData(0, "正在招标", "再次投标", View.GONE);
                    } else if ("15".equals(tenderInfoMainEntity3.getApplyStates())) {
                        updateViewData(1, "正在招标", "我要投标", View.GONE);
                    } else{
                        updateViewData(0, "正在招标", "我要投标", View.GONE);
                    }
                }
            }


        } else if (tenderInfoMainEntity3.getState() == 3) {   // 竞标评标

            if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                updateViewData(1, "竞标评标", "我要投标", View.GONE);
            } else {
                binding.tvIsApply.setText("竞标评标");
                if (!tenderDetailEntity3.getTenderAuthority()) {
                    if (rotation == 1) {
                        if (tenderInfoMainEntity3.getVerticalTypeValue() == 3) {
                            if ("0".equals(tenderInfoMainEntity3.getApplyStates()) && tenderInfoMainEntity3.ischeckApplay()) {
                                updateViewData(1, "", "我要投标", View.VISIBLE);
                            }
                            if ("20".equals(tenderInfoMainEntity3.getApplyStates())) {
                                updateViewData(1, "", "我要投标", View.GONE);
                            }
                        } else {
                            updateViewData(1, "", "我要投标", View.GONE);
                        }
                    } else if (rotation >= 2) {
                        updateViewData(1, "", "我要投标", View.GONE);
                    }
                }
            }

            binding.imgEnd.setVisibility(View.GONE);
            if (!TextUtils.isEmpty(tenderInfoMainEntity3.getBidTime())) {
                String st = DateUtils.stampToDatePick(tenderInfoMainEntity3.getBidTime());
                binding.tvEndTime.setText("开标时间: " + st);
            } else {
                binding.tvEndTime.setText("开标时间: ");
            }

            // 因2.8版bidRotation改为招标详情中显示的轮次，防止误显示
//            binding.tvTurns.setText("本轮为第" + tenderInfoMainEntity3.getBidRotation() + "轮竞标");
//            binding.tvTurns.setVisibility(View.VISIBLE);

        } else if (tenderInfoMainEntity3.getState() == 4) {  //招标定标

            //未登录同登录
            updateViewData(1, "招标定标", "我要投标", View.GONE);

            binding.imgEnd.setVisibility(View.GONE);
            if (!TextUtils.isEmpty(tenderInfoMainEntity3.getWinningTime())) {
                String st = DateUtils.stampToDatePick(tenderInfoMainEntity3.getWinningTime());
                binding.tvEndTime.setText("定标时间: " + st);
            } else {
                binding.tvEndTime.setText("定标时间: ");
            }

            binding.tvBidCompany.setText("中标单位: " + tenderInfoMainEntity3.getWinningName());
            binding.tvBidCompany.setVisibility(View.VISIBLE);

        } else if (tenderInfoMainEntity3.getState() == 5) {

            updateViewData("废标", tenderInfoMainEntity3.getReason(),tenderInfoMainEntity3.getUpdated());

        } else if (tenderInfoMainEntity3.getState() == 7) {

            updateViewData("流标", tenderInfoMainEntity3.getReason(),tenderInfoMainEntity3.getUpdated());

        } else if (tenderInfoMainEntity3.getState() == 8) {

            updateViewData(1, "招标预告", "报名", View.GONE);

        } else if (tenderInfoMainEntity3.getState() == 10) {

            if (tenderInfoMainEntity3.getEndTime() != null)
                timeBefore(tenderInfoMainEntity3.getEndTime(), "报名结束倒计时：");

            updateViewData(1, "资格审查中", "报名", View.GONE);
        }


        if (tenderDetailEntity3.getTenderAuthority()) {
            binding.tvCommit.setText("业主");
            binding.tvCommit.setBackground(getResources().getDrawable(R.drawable.bg_shap_color_change_2corner));
            binding.tvCommit.setEnabled(true);
            binding.llApplication.setVisibility(View.GONE);
        }

    }

    private void updateViewData(int tvCommitBg, String tvIsApplyText, String tvCommitText, int applicationVisible) {
        binding.bottomLayout.setVisibility(View.VISIBLE);
        binding.fbLbLine.setVisibility(View.GONE);
        binding.lineTime.setVisibility(View.VISIBLE);
        
        if (tvIsApplyText != "") {
            binding.tvIsApply.setVisibility(View.VISIBLE);
            binding.tvIsApply.setText(tvIsApplyText);
        }

        if (tvCommitText != "") {
            binding.tvCommit.setText(tvCommitText);
            if (tvCommitBg == 0) {
                binding.tvCommit.setBackground(getResources().getDrawable(R.drawable.tender_details));
                binding.tvCommit.setEnabled(true);
            } else if (tvCommitBg == 1) {
                binding.tvCommit.setBackground(getResources().getDrawable(R.drawable.tender_dateils_unclick));
                binding.tvCommit.setEnabled(false);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    binding.tvCommit.setBackground(getDrawable(R.drawable.tender_dateils_unclick));
                }
            }
        }
        binding.llApplication.setVisibility(applicationVisible);
    }

    private void updateViewData(String type, String reason, String updatedTime) {
        binding.bottomLayout.setVisibility(View.GONE);
        binding.fbLbLine.setVisibility(View.VISIBLE);
        binding.lineTime.setVisibility(View.GONE);

        if (type != "") {
            binding.tvIsApply.setVisibility(View.VISIBLE);
            binding.tvIsApply.setText(type);
        }

        if (!TextUtils.isEmpty(updatedTime)) {
            binding.fbTimeLine.setVisibility(View.VISIBLE);
            binding.timeTitle.setText(type + "时间");
            binding.timeContent.setText(updatedTime);
        }
        if (!TextUtils.isEmpty(reason)) {
            binding.fbReasonLine.setVisibility(View.VISIBLE);
            binding.reasonTitle.setText(type + "原因");
            binding.reasonContent.setText(reason);
            new ExpandedTextView().showTextPick(binding.timeContent, binding.expandView);
        }

    }
    
    /**
     * 初始化 底部布局
     *
     * @param tenderDetailEntity3
     */
    private void initTabView(TenderDetailEntity3 tenderDetailEntity3) {
        setTitleData();
    }

    /**
     * 根据招标补遗请求数据来区分要不要显示招标补遗tab，同时需要根据不同的材料类型来重新对tab的第一个位置重命名
     */
    private void setTitleData() {

        titles.clear();
        if (TextUtils.isEmpty(tenderDetailEntity3.getTenderInfoMainEntity3().getTypeName())) {
            binding.tvTenderType.setVisibility(View.GONE);
        } else {
            binding.tvTenderType.setVisibility(View.VISIBLE);
            binding.tvTenderType.setText(tenderDetailEntity3.getTenderInfoMainEntity3().getTypeName());
        }
        // “6勘察设计”、“7建筑设计”、“8工程监理”、“9工程造价咨询”、“10工程总承包”时   没有招标清单，默认展示【投标人资格tab】
        int type = tenderDetailEntity3.getTenderInfoMainEntity3().getType();
        //招标清单
        if (tenderDetailEntity3.getTenderInfoMainEntity3().getGoodsList() != null && tenderDetailEntity3.getTenderInfoMainEntity3().getGoodsList().size() > 0) {
            if (type == 6 || type == 7 || type == 8 || type == 9 || type == 10 || type == 13 || type == 20) {
                haveList = false;
            } else {
                haveList = true;
                titles.add("招标清单");
                if (1 == type) {
                    binding.tvTenderType.setText("机械租赁");
                    titles.set(0, "机械清单");
                } else if (2 == type) {
                    binding.tvTenderType.setText("劳务分包");
                    titles.set(0, "劳务清单");
                } else if (3 == type) {
                    binding.tvTenderType.setText("商品&材料");
                    titles.set(0, "材料清单");
                } else if (4 == type) {
                    binding.tvTenderType.setText("工程分包");
                    titles.set(0, "工程清单");
                } else if (11 == type || 15 == type) {
                    titles.set(0, "房产清单");
                } else if (12 == type || 18 == type) {
                    titles.set(0, "车辆清单");
                } else if (14 == type) {
                    titles.set(0, "土地清单");
                } else if (16 == type) {
                    titles.set(0, "机械清单");
                } else if (17 == type) {
                    titles.set(0, "设备清单");
                } else if (19 == type) {
                    titles.set(0, "运输清单");
                }
            }
        } else {
            haveList = false;
        }
        //招标公告
        if (tenderDetailEntity3.getTenderInfoBasicEntity3() != null && tenderDetailEntity3.getTenderInfoBasicEntity3().size() > 0) {
            titles.add("招标公告");
            haveOffer = true;
        } else {
            haveOffer = false;
        }
        //招标补遗
        if (tenderAddenduEntityList != null && tenderAddenduEntityList.size() > 0) {
            titles.add("招标补遗");
            haveAddendu = true;
        } else {
            haveAddendu = false;
        }
        //函询
        if (tenderInquiryTypeList != null && tenderInquiryTypeList.size() > 0) {
            titles.add("函询");
            haveInquireByLetter = true;
        } else {
            haveInquireByLetter = false;
        }

        binding.tablayout.removeAllTabs();
        for (String title : titles) {
            binding.tablayout.addTab(binding.tablayout.newTab().setText(title));
        }
        for (int i = 0; i < binding.tablayout.getTabCount(); i++) {
            TabLayout.Tab tab = binding.tablayout.getTabAt(i);
            if (tab != null) {
                try {
                    //这里使用到反射，拿到Tab对象后获取Class
                    Class c = tab.getClass();
                    Field field = c.getDeclaredField("view");
                    field.setAccessible(true);
                    final View tabView = (View) field.get(tab);
                    if (tabView == null) return;
                    tabView.setTag(i);
                    tabView.setOnClickListener(mTabOnClickListener);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        if (titles.size() > 4) {
            binding.tablayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        } else {
            if (titles.size() == 4 && titles.contains("投标人资格")) {
                binding.tablayout.setTabMode(TabLayout.MODE_SCROLLABLE);
            } else {
                binding.tablayout.setTabMode(TabLayout.MODE_FIXED);
            }
        }

        showInfoView(tenderDetailEntity3);

    }

    private void showInfoView(TenderDetailEntity3 tenderDetailEntity3) {
        List<View> list = new ArrayList<>();
        try {
            if (haveList) {
                //招标清单
                PickBiddinglistDetaiView pickBiddinglistDetaiView = new PickBiddinglistDetaiView(getActivity());
                pickBiddinglistDetaiView.setText(titles.get(0));
                pickBiddinglistDetaiView.showInfoView(tenderDetailEntity3.getTenderInfoListEntity3().getTenderInfoItemEntity3(), true, tenderDetailEntity3.getTenderInfoMainEntity3().getType(),
                        UrlConfig.BASE_URL_ZC_DO + "sgb-zhaocai/ov1/mechanicalLabor/exportGoodsExcel/" + tenderId ,tenderDetailEntity3.getGoodsFiles(),tenderDetailEntity3.getTenderInfoListEntity3().isMore(),
                        tenderId,tenderDetailEntity3.getTenderInfoMainEntity3().getName());
                list.add(pickBiddinglistDetaiView);
            }
            if(haveOffer){
                //招标公告
                PickDetailRuleView pickDetailOfferView = new PickDetailRuleView(getActivity(),"招标公告");
                pickDetailOfferView.showInfoView(tenderDetailEntity3.getTenderInfoBasicEntity3(),tenderDetailEntity3.getTenderInfoMainEntity3().getName());
                pickDetailOfferView.showMainInfoView(tenderDetailEntity3.getTenderInfoMainEntity3(),tenderDetailEntity3.getTenderRar(),tenderDetailEntity3.getTenderingFiles(),this);
                list.add(pickDetailOfferView);
            }
            if (haveAddendu) {
                //招标补遗
                PickDetailSupplementView pickDetailSupplementView = new PickDetailSupplementView(getActivity());
                pickDetailSupplementView.showInfoView(tenderAddenduEntityList, viewModel, tenderId, binding.topLayout.titleView.getText().toString());
                list.add(pickDetailSupplementView);
            }
            if (haveInquireByLetter) {
                //函询
                PickDetailInquiryView pickDetailInquiryView = new PickDetailInquiryView(getActivity());
                pickDetailInquiryView.showInfoView(tenderInquiryTypeList, tenderId, binding.topLayout.titleView.getText().toString());
                list.add(pickDetailInquiryView);
            }

            if (list.size() == 0) {
                binding.tablayout.setVisibility(View.GONE);
            } else {
                binding.tablayout.setVisibility(View.VISIBLE);
                LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
                binding.recyclerViewContent.setLayoutManager(layoutManager);
                PickAddViewAdapter pickAddViewAdapter = new PickAddViewAdapter(getActivity(), list, R.layout.item_pick_add_child);
                binding.recyclerViewContent.setAdapter(pickAddViewAdapter);
                binding.recyclerViewContent.addOnScrollListener(new RecyclerView.OnScrollListener() {
                    @Override
                    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                        super.onScrolled(recyclerView, dx, dy);
                        if (scrolledFirst) {
                            scrolledFirst = false;
                            return;
                        } else {
                            //调用方法
                            LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
                            selectPos = layoutManager.findFirstVisibleItemPosition();
                            if (isSlideToBottom(recyclerView)) { //滑倒底部
                                selectPos = titles.size() - 1;
                            }
                            postDelayedSelect(selectPos);
                        }
                    }
                });
            }

        } catch (Exception e) {
            MLog.e("TenderDetailsActivity3.showInfoView", e.toString());
        }
    }

    /**
     * 获取RecyclerView滚动距离
     */
    private int getDistance() {
        LinearLayoutManager layoutManager = (LinearLayoutManager) binding.recyclerViewContent.getLayoutManager();
        View firstVisibItem = binding.recyclerViewContent.getChildAt(0);
        int firstItemPosition = layoutManager.findFirstVisibleItemPosition();
        int itemCount = layoutManager.getItemCount();
        int recycleViewHeight = binding.recyclerViewContent.getHeight();
        int itemHeight = firstVisibItem.getHeight();
        int firstItemBottom = layoutManager.getDecoratedBottom(firstVisibItem);
        return (itemCount - firstItemPosition - 1) * itemHeight - recycleViewHeight;
    }

    /**
     * 监听RecyclerView是否滑动到底部
     *
     * @param recyclerView
     * @return
     */
    private boolean isSlideToBottom(RecyclerView recyclerView) {
        if (recyclerView == null) return false;
        if (recyclerView.computeVerticalScrollExtent() + recyclerView.computeVerticalScrollOffset() >= recyclerView.computeVerticalScrollRange())
            return true;
        return false;
    }

    private void postDelayedSelect(int selectPos) {
//        binding.tablayout.postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                binding.tablayout.getTabAt(selectPos).select();
//            }
//        }, 100);
        if (selectPos <= (titles.size() - 1)) {
            binding.tablayout.getTabAt(selectPos).select();
        }
    }

    private View.OnClickListener mTabOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectPos = (int) view.getTag();
            TabLayout.Tab tab = binding.tablayout.getTabAt(selectPos);
            if (tab != null) {
                tab.select();
            }
//            if (selectPos == 0) {
//                //顶部
//                smoothMoveToPosition(binding.recyclerViewContent, selectPos);
//            } else if (selectPos == 1) {
//                smoothMoveToPosition(binding.recyclerViewContent, selectPos);
//            } else if (selectPos == 2) {
//                smoothMoveToPosition(binding.recyclerViewContent, selectPos);
//            } else if (selectPos == 3) {
//                smoothMoveToPosition(binding.recyclerViewContent, selectPos);
//            } else if(selectPos == 4){
//                smoothMoveToPosition(binding.recyclerViewContent, selectPos);
//            }

//            smoothMoveToPosition(binding.recyclerViewContent, selectPos);
            MoveToPosition((LinearLayoutManager) binding.recyclerViewContent.getLayoutManager(), binding.recyclerViewContent, selectPos);
            scrollToTop(false);
        }
    };


    public static void MoveToPosition(LinearLayoutManager manager, RecyclerView mRecyclerView, int n) {

        int firstItem = manager.findFirstVisibleItemPosition();
        int lastItem = manager.findLastVisibleItemPosition();
        if (n <= firstItem) {
            mRecyclerView.scrollToPosition(n);
        } else if (n <= lastItem) {
            int top = mRecyclerView.getChildAt(n - firstItem).getTop();
            mRecyclerView.scrollBy(0, top);
        } else {
            mRecyclerView.scrollToPosition(n);
        }

    }

    /**
     * 滑动到指定位置
     */
    private void smoothMoveToPosition(RecyclerView mRecyclerView, final int position) {
        // 第一个可见位置
        int firstItem = mRecyclerView.getChildLayoutPosition(mRecyclerView.getChildAt(0));
        // 最后一个可见位置
        int lastItem = mRecyclerView.getChildLayoutPosition(mRecyclerView.getChildAt(mRecyclerView.getChildCount() - 1));
        if (position < firstItem) {
            // 第一种可能:跳转位置在第一个可见位置之前，使用smoothScrollToPosition
            mRecyclerView.smoothScrollToPosition(position);
        } else if (position <= lastItem) {
            // 第二种可能:跳转位置在第一个可见位置之后，最后一个可见项之前
            int movePosition = position - firstItem;
            if (movePosition >= 0 && movePosition < mRecyclerView.getChildCount()) {
                int top = mRecyclerView.getChildAt(movePosition).getTop();
                // smoothScrollToPosition 不会有效果，此时调用smoothScrollBy来滑动到指定位置
                mRecyclerView.smoothScrollBy(0, top);
            }
        } else {
            // 第三种可能:跳转位置在最后可见项之后，则先调用smoothScrollToPosition将要跳转的位置滚动到可见位置
            // 再通过onScrollStateChanged控制再次调用smoothMoveToPosition，执行上一个判断中的方法
            mRecyclerView.smoothScrollToPosition(position);
        }
    }

    /**
     * 实现AppBarLayout快速滚动
     *
     * @param flag true，滚动到顶部：false 滑动到吸顶效果
     */
    private void scrollToTop(boolean flag) {
        CoordinatorLayout.Behavior behavior =
                ((CoordinatorLayout.LayoutParams) binding.appBarLayout.getLayoutParams()).getBehavior();
        if (behavior instanceof AppBarLayout.Behavior) {
            AppBarLayout.Behavior appBarLayoutBehavior = (AppBarLayout.Behavior) behavior;
            if (flag) {
                appBarLayoutBehavior.setTopAndBottomOffset(0); //快熟滑动到顶部
            } else {
                int hight = binding.appBarLayout.getHeight();
                appBarLayoutBehavior.setTopAndBottomOffset(-hight);//快速滑动实现吸顶效果
            }
        }
    }


    public void setIsGz(boolean isGz) {
        NumberConstant.sIsChangeForTeam = 1;
        if (isGz) {
            binding.focusState.setText("关注");
            binding.focusState.setTextColor(getResources().getColor(R.color.color_main));
            binding.focusState.setBackgroundResource(R.drawable.corner5_ff2928_bg_pick);
            viewModel.tenderInfoMainEntity3.get().setConcernEnterprises(false);
            MToast.showLongToast1(this, "已取消关注企业", Gravity.CENTER);
        } else {
            binding.focusState.setText("已关注");
            binding.focusState.setTextColor(getResources().getColor(R.color.color_999999));
            binding.focusState.setBackgroundResource(R.drawable.corner5_999999_bg);
            viewModel.tenderInfoMainEntity3.get().setConcernEnterprises(true);
            MToast.showLongToast1(this, "关注企业成功", Gravity.CENTER);
        }
    }

    public void setTvIsGz(int isGz) {
        success=true;
        //标是否关注
        if (isGz == 1) {
            viewModel.tenderInfoMainEntity3.get().setUserFocusFlag(0);
            MToast.showLongToast1(this, "已取消关注招标", Gravity.CENTER);
        } else {
            viewModel.tenderInfoMainEntity3.get().setUserFocusFlag(1);
            MToast.showLongToast1(this, "关注招标成功", Gravity.CENTER);
        }
        updateUserFocusBg();
    }

    private void updateUserFocusBg() {
        //标是否关注
        if (viewModel.tenderInfoMainEntity3.get().getUserFocusFlag() == 0) {
            binding.imageUserFocus.setBackgroundResource(R.mipmap.guanzhu_pick);
            binding.tvUserFocus.setText("关注");
            binding.tvUserFocus.setTextColor(getResources().getColor(R.color.color_tab_one));
        } else {
            binding.imageUserFocus.setBackgroundResource(R.mipmap.yiguanzhu_pick);
            binding.tvUserFocus.setText("已关注");
            binding.tvUserFocus.setTextColor(getResources().getColor(R.color.color_main));
        }
    }

    public void timeBefore(String time, String info) {
        String st = DateUtils.stampToDate(time);//结束或者开始时间
        String nt = DateUtils.stampToDate(System.currentTimeMillis() + "");//当前时间
        Timestamp t = Timestamp.valueOf(st);
        Timestamp n = Timestamp.valueOf(nt);
        if (n.before(t)) {
            //没过期
            long nl = System.currentTimeMillis();
            long sl = (long) Long.valueOf(time);
            time2((sl - nl) / 1000, info);
        } else {
            binding.tvEndTime.setText("投标已截止");
        }
    }

    public void time2(long midTime, String info) {
        this.midTime = midTime;
        this.info = info;
        runnable.run();
    }

    private Runnable runnable = new Runnable() {

        private String time;

        @Override
        public void run() {
            if (midTime > 0) {
                midTime--;
                /*long dd = midTime / 24 / 60 / 60 % 60;
                long hh = (midTime - dd * 24 * 60 * 60) / 60 / 60 % 60;
                long mm = (midTime - dd * 24 * 60 * 60 - hh * 60 * 60) / 60 % 60;
                long ss = midTime % 60;*/
                long dd = midTime / 86400;
                long hh = midTime % 86400 / 3600;            //转换小时
                long mm = midTime % 86400 % 3600 / 60;            //转换分钟
                long ss = midTime % 86400 % 3600 % 60;            //剩余秒数

                if (dd > 0) {
                    time = info + dd + "天" + hh + "小时" + mm + "分钟" + ss + "秒";
                } else {
                    if (hh > 0) {
                        time = info + hh + "小时" + mm + "分钟" + ss + "秒";
                    } else {
                        if (mm > 0) {
                            time = info + mm + "分钟" + ss + "秒";
                        } else {
                            time = info + ss + "秒";
                        }
                    }
                }
                Message message = Message.obtain();
                message.what = 1;
                message.obj = time;
                timeHandler.sendMessage(message);
//                Log.e("倒计时", time);
                timeHandler.postDelayed(runnable, 1000);
            } else {
                timeHandler.removeCallbacks(runnable);
            }
        }
    };

    @SuppressLint("HandlerLeak")
    private Handler timeHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                binding.tvEndTime.setText((String) msg.obj);
            }
        }
    };

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_application: //申请
                if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                    jumpLogin();
                } else {
                    viewModel.checkTenderBidApply(viewModel.tenderInfoMainEntity3.get().getId());
                }
                break;
            case R.id.tv_commit:
               /* if (toLogin) {
                    showDialog(); // 展示跳往登录页面的弹窗
                } else {
                    checkAddTokenView();
                }*/

                if (tenderDetailEntity3 != null && tenderDetailEntity3.getTenderAuthority()) {
                    viewModel.tenderRecordCount(tenderId);
                } else {
                    if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                        jumpLogin();
                        //VerificationCodeLoginActivity.start(MainActivity.this);
                    } else {
                        checkAddTokenView();
                    }
                    updateData = true;
                }
                break;
            case R.id.tv_contact_service:
                // 招标详情交流
                /*  1、如果没有咨询客服，点击提示：“招标方未设置客服人员，不支持交流”；

                    2、用户未登录时：点击按钮前往登录；

                    3、用户已登录：点击打开IM，与发布时添加的“咨询客服”聊天；

                    4、个人/企业都可以聊天*/

                if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                    jumpLogin();
                } else {
                    // 跳转H5聊天
                    if (!TextUtils.isEmpty(customerServiceContactsId)) {
                        viewModel.findCustomerServiceImAccount(customerServiceContactsId);
                    } else {
                        checkAllowDialog("招标方未设置客服人员，不支持交流。");
                    }
                }
                break;
            case R.id.tv_inquire_by_letter:
                // 招标 竞标 详情函询
                if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                    jumpLogin();
                } else {
//                    viewModel.checkToken("");
                    // 验证当前用户是否允许函询--招标
                    // http://app.gcw.net:3000/mock/113/v3/app/recruit/checkAllowTenderQuestion
                    if (tenderDetailEntity3.getTenderInfoMainEntity3() != null) {
                        viewModel.checkAllowTenderQuestion(tenderId, tenderDetailEntity3.getTenderInfoMainEntity3().getType());
                    }
                }
                break;
            case R.id.tv_report:
                ReportActivity.start(this, tenderId, "1");
                break;
            case R.id.pick_company:
                if (TextUtils.isEmpty(viewModel.tenderInfoMainEntity3.get().getComNo())) {
                    ToastUtil.show(TenderDetailsActivity3.this, "企业店铺no不能为空");
                    return;
                }
                WebsiteInfoActivity.start(getActivity(), viewModel.tenderInfoMainEntity3.get().getComNo(), WebsiteInfoActivity.WEBSITE_FOR_COMPANY);
                break;
            case R.id.focusState:
                type = 0;
                comType = 0;
                if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                    jumpLogin();
                } else {
                    focusEnterprise();
                }
                break;
            case R.id.line_user_focus:
                type = 1;
                if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                    jumpLogin();
                } else {
                    focusEnterprise();
                }
                break;
            case R.id.img_back_top:
                CoordinatorLayout.Behavior behavior =
                        ((CoordinatorLayout.LayoutParams) binding.appBarLayout.getLayoutParams()).getBehavior();
                if (behavior instanceof AppBarLayout.Behavior) {
                    AppBarLayout.Behavior appBarLayoutBehavior = (AppBarLayout.Behavior) behavior;
                    int topAndBottomOffset = appBarLayoutBehavior.getTopAndBottomOffset();
                    if (topAndBottomOffset != 0) {
                        appBarLayoutBehavior.setTopAndBottomOffset(0);
                        binding.appBarLayout.setExpanded(true, true);
                    }
                }
                break;
            case R.id.share_image_view:
                if (!ClickUtils.isDoubleClick()) {
                    PickEmploymentShareDialog dialog = new PickEmploymentShareDialog(tenderDetailEntity3.getTenderInfoMainEntity3().getName(), tenderDetailEntity3.getTenderInfoMainEntity3().getWeixinFenXiangUrl(),
                            tenderDetailEntity3.getTenderInfoMainEntity3().getWeixinFenXiangMsg(), tenderDetailEntity3.getTenderInfoMainEntity3().getTypeName(), tenderDetailEntity3.getTenderInfoMainEntity3().getMoney().toString()
                            , tenderDetailEntity3.getTenderInfoMainEntity3().getComName(), 1, this, null);
                    dialog.setDialogClickCallBack(new PickEmploymentShareDialog.DialogClickCallBack() {
                        @Override
                        public void onItemClick(String name) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    ToastUtil.show(TenderDetailsActivity3.this, name);
                                }
                            });
                        }
                    }).show();
                }
                break;
            default:
                break;
        }
    }

    public void getTenderRecordCount(PickRecordCount pickRecordCount) {
        tenderDetailsPopWindow = new TenderDetailsPopWindow(getActivity(), 3, pickRecordCount);
        tenderDetailsPopWindow.setBgView(binding.grayLayout);
        tenderDetailsPopWindow.showPopwindowBottom(binding.tvCommit);
        viewModel.getUrlSetting(tenderId);
    }

    public void getUrl(String url) {
        tenderDetailsPopWindow.setCallBack(new TenderDetailsPopWindow.CallBack() {
            @Override
            public void onLoad(int id) {
                tenderDetailsPopWindow.dismiss();
                if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                    jumpLogin();
                } else {
                    WebViewX5HostActivity.start(TenderDetailsActivity3.this, url + id);
                }
            }
        });
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(MachinePublishEvent event) {
        if (event.getMessageTag() == EventConstant.EVENT_ENTERPRISE_BIDDING_COMMIT) {
            //  viewModel.getRecommendListModel(no);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    public void jumpLogin() {
        boolean shanyan = MkvUtils.get().getBoolean(MkvUtils.CommomData, CacheMarker.ShanYan, false);
        if (shanyan) {
            //校验权限
            //申请动态权限
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                //6.0以上运行时权限处理
                EsayPermissions.with(TenderDetailsActivity3.this).constantRequest().permission(PERMISSIONS).request(new OnPermission() {
                    @Override
                    public void hasPermission(List<String> granted, boolean isAll) {
                        openLoginPage();
                    }

                    @Override
                    public void noPermission(List<String> denied, boolean quick) {
                        openLoginPage();
                    }
                });

            } else {
                //有权限
                openLoginPage();
            }

        } else {
            VerificationCodeLoginActivity.start(TenderDetailsActivity3.this, EventConstant.EVENT_TENDER_DETAILS_3_JUMP);
        }
    }

    //闪验
    static final String[] PERMISSIONS = new String[]{
            Manifest.permission.READ_PHONE_STATE
    };

    /**
     * 拉起授权页
     */
    private void openLoginPage() {
        //设置授权页样式
        OneKeyLoginManager.getInstance().setAuthThemeConfig(ConfigUtils.getCJSConfig(this));
        //开始拉取授权页
        DialogHelper.showProgressDialog(this, null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(true);
        OneKeyLoginManager.getInstance().openLoginAuth(false, new OpenLoginAuthListener() {
            @Override
            public void getOpenLoginAuthStatus(int code, String result) {
                DialogHelper.dismissProgressDialog();
                if (code != 1000) {
                    VerificationCodeLoginActivity.start(TenderDetailsActivity3.this, EventConstant.EVENT_TENDER_DETAILS_3_JUMP);
                }
            }
        }, new OneKeyLoginListener() {
            @Override
            public void getOneKeyLoginStatus(int code, String result) {
                DialogHelper.dismissProgressDialog();
                if (code == 1000) {
                    OneKeyLoginEntity oneKeyLoginEntity = GsonManager.getInstance().getGson().fromJson(result, OneKeyLoginEntity.class);
                    oneKeyLoginEntity.setPlateform("Android");
                    viewModel.oneKeyLogin(oneKeyLoginEntity);
                }
            }
        });
    }

    /**
     * 一键登录成功
     *
     * @param loginEntity
     * @param phoneNumber
     */
    public void loginSucceed(LoginEntity loginEntity, String phoneNumber) {
        LoginEvent loginEvent = new LoginEvent();
        loginEvent.setMessageData(phoneNumber);
        loginEvent.setMessageTag(EventConstant.EVENT_TENDER_DETAILS_3_JUMP);
        loginEvent.setObject(loginEntity);
        EventBus.getDefault().postSticky(loginEvent);
    }

    public void getUserMsgSucceed(UserMsgEntity userMsgEntity) {
        LoginEvent loginEvent = new LoginEvent();
        loginEvent.setMessageTag(EventConstant.EVENT_USER_MSG);
        loginEvent.setMessageData(userMsgEntity);
        EventBus.getDefault().postSticky(loginEvent);
    }

    public void checkAddTokenView() {
        //正常报名，招标，竞标
        if (viewModel.tenderInfoMainEntity3.get().getState() == 9) {//报名
            viewModel.checkAllowApply(viewModel.tenderInfoMainEntity3.get().getId());
        } else {
            viewModel.checkAllowBid(viewModel.tenderInfoMainEntity3.get().getId());
        }
    }

    /**
     * 企业关注
     */
    public void focusEnterprise() {
        if (type == 0) {//关注企业
            viewModel.userFocus(viewModel.tenderInfoMainEntity3.get().getComNo(), viewModel.tenderInfoMainEntity3.get().isConcernEnterprises(), comType);
        } else {
            viewModel.editTender(tenderId, viewModel.tenderInfoMainEntity3.get().getUserFocusFlag());
        }
    }

    public void checkAllowBid(String categoryModel) {
        EnterpriseBiddingActivity5.start(
                this,
                categoryModel,
                viewModel.tenderInfoMainEntity3.get().getId(),
                viewModel.tenderInfoMainEntity3.get().getVerticalTypeValue(),
                viewModel.tenderInfoMainEntity3.get().getState(),
                viewModel.tenderInfoMainEntity3.get().getLat(),
                viewModel.tenderInfoMainEntity3.get().getLng()
        );
//        if (viewModel.tenderInfoMainEntity3.get().getVerticalTypeValue() == 3 && viewModel.tenderInfoMainEntity3.get().getState() == 9) {
//            EnterpriseBiddingActivity5.start(this, viewModel.tenderInfoMainEntity3.get().getId(),viewModel.tenderInfoMainEntity3.get().getVerticalTypeValue());
////            EnterpriseBiddingActivity4.start(this, viewModel.tenderInfoMainEntity3.get().getId());
//        } else {
//            EnterpriseBiddingActivity3.start(this, viewModel.tenderInfoMainEntity3.get().getId(), viewModel.tenderInfoMainEntity3.get().getState());
//        }
    }

    public void checkTokenView() {
        Intent intent = new Intent();
        intent.putExtra("showPage", "FRAGMENT_SHOPPING");
        MainActivity.start(TenderDetailsActivity3.this, intent);

    }

    public void toLogin() {
        SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.LOGIN_TOKEN, "");
        SharedPreferenceUtil.getInstance().saveData(SharedPreferenceUtil.LOGIN_PHONE, "");
        MToast.showToast(this, "登录失效，请重新登录");
        //LoginActivity.start(this);
        jumpLogin();
    }

    private void showDialog() {
        View view = View.inflate(getActivity(), R.layout.dialog_two_btn, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(getActivity(), 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
        //roundCornerDialog.setOnKeyListener(keylistener);//设置点击返回键Dialog不消失

        TextView tv_message = view.findViewById(R.id.tv_message);
        TextView tv_title = view.findViewById(R.id.tv_title);
        TextView tv_logout_confirm = view.findViewById(R.id.tv_logout_confirm);
        TextView tv_logout_cancel = view.findViewById(R.id.tv_logout_cancel);
        tv_title.setText("提示");
        tv_title.setVisibility(View.VISIBLE);
        tv_message.setText("请登录后查看");

        //确定
        tv_logout_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                roundCornerDialog.dismiss();
                jumpLogin();
            }
        });
        //取消
        tv_logout_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                roundCornerDialog.dismiss();
            }
        });
    }

    public void checkAllowDialog(String msg) {
        View view = View.inflate(getActivity(), R.layout.dialog_two_btn, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(getActivity(), 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
        TextView tv_message = view.findViewById(R.id.tv_message);
        TextView tv_title = view.findViewById(R.id.tv_title);
        TextView tv_logout_confirm = view.findViewById(R.id.tv_logout_confirm);
        TextView tv_logout_cancel = view.findViewById(R.id.tv_logout_cancel);

        tv_logout_cancel.setVisibility(View.GONE);
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("提示");

        tv_message.setText(msg);

        //确定
        tv_logout_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                roundCornerDialog.dismiss();
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        String localLng = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "");
        String localLat = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "");
        if (localLng == "" && localLat == "") {
            getLoction();
        }
        if(updateData){
            viewModel.getPickBidDetailModel(tenderId);
        }
    }


    private void getLoction() {
        if (mapLocationTools == null){
            mapLocationTools = new MapLocationTools(getActivity());
        }
        mapLocationTools.initLocation(false);
        mapLocationTools.setLocationListener(new MapLocationTools.LocationListener() {
            @Override
            public void getLocationListener(String address, Double Longitude, Double Latitude) {
                SharedPreferenceUtil.getInstance().saveString(SharedPreferenceUtil.LONGITUDE_ID,String.valueOf(Longitude));
                SharedPreferenceUtil.getInstance().saveString(SharedPreferenceUtil.LATITUDE_ID,String.valueOf(Latitude));
            }
        });
        mapLocationTools.startLocation();
    }

    @Override
    public void onBackPressed() {
        if (success) {
            Intent intent = new Intent();
            if (viewModel.tenderInfoMainEntity3.get().getUserFocusFlag() == 0) {
                intent.putExtra("isFocus", false);
            }else{
                intent.putExtra("isFocus", true);
            }
            setResult(3,intent);

        }
        super.onBackPressed();
    }
}

